﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace TestControl
{
    public class SelectablePanel:Panel
    {
        

        private Pen borderPen;
        private Brush br;
        public SelectablePanel()
        {
            br = Brushes.Red;
            borderPen = new Pen(br);
            borderPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;

            this.Click += new EventHandler(SelectablePanel_Click);
        }

        void SelectablePanel_Click(object sender, EventArgs e)
        {
            if (br == Brushes.Red)
            {
                br = Brushes.Blue;
            }
            else
            {
                br = Brushes.Red;
            }
            borderPen = new Pen(br);
            borderPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            this.Invalidate();
        }



        protected override void OnPaint(PaintEventArgs e)

        {
            base.OnPaint(e);
            e.Graphics.DrawRectangle(borderPen,
                                    e.ClipRectangle.Left,
                                    e.ClipRectangle.Top,
                                    e.ClipRectangle.Width-1 ,
                                    e.ClipRectangle.Height-1);
            e.Graphics.DrawRectangle(borderPen,
                                    e.ClipRectangle.Left+2,
                                    e.ClipRectangle.Top+2,
                                    e.ClipRectangle.Width - 5,
                                    e.ClipRectangle.Height - 5);
        }
    }
}
